package geowiki.threads;

import geowiki.utils.Integrator;
import processing.core.PApplet;
import processing.core.PConstants;
import processing.core.PImage;

public class AppearingImage {

	protected PApplet p;

	protected PImage image;

	protected Integrator sizeIntegrator;
	protected Integrator xIntegrator;
	protected Integrator yIntegrator;

	float x;
	float y;
	float width = 100;
	float height = 100;

	public AppearingImage(PApplet p, PImage image, float x, float y) {
		this.p = p;

		this.image = image;
		this.x = x;
		this.y = y;

		sizeIntegrator = new Integrator();
		sizeIntegrator.set(0);
		sizeIntegrator.target(width);

		xIntegrator = new Integrator();
		xIntegrator.set(x);
		xIntegrator.target(x);

		yIntegrator = new Integrator();
		yIntegrator.set(y);
		yIntegrator.target(y);
	}

	public void draw() {
		float s = sizeIntegrator.value;
		p.imageMode(PConstants.CENTER);
		p.image(image, xIntegrator.value, yIntegrator.value, s, s);
	}

	public void update() {
		sizeIntegrator.update();
		xIntegrator.update();
		yIntegrator.update();
	}

	public void zoomIn() {
		sizeIntegrator.target(500);
		xIntegrator.target(p.width / 2);
		yIntegrator.target(p.height / 2);
	}

	public void zoomOut() {
		sizeIntegrator.target(100);
		xIntegrator.target(x);
		yIntegrator.target(y);
	}

	public boolean isOver(float checkX, float checkY) {
		return checkX > (x - width / 2) && checkX < (x + width / 2) && checkY > (y - height / 2)
				&& checkY < (y + height / 2);
	}

}
